import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yn_goods/widgets/button/common_button.dart';
import 'package:flutter_yn_goods/widgets/empty_view.dart';
import 'package:flutter_yn_goods/widgets/image/auto_image.dart';
import 'package:transparent_pointer/transparent_pointer.dart';


import '../../../generated/assets.dart';


mixin BaseLoadingMixin on Widget {
  Widget buildLoading() {
    return Center(
      child: Padding(
        padding: const EdgeInsets.only(bottom: 50),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const AutoImage(Assets.hudLoading, width: 84),
            const SizedBox(height: 8),
            Text("加载中…",
                style: TextStyle(
                    fontSize: 12, color: Colors.white.withOpacity(0.6))),
          ],
        ),
      ),
    );
  }

  Widget buildEmptyWithButton(
      {String? title,
      String? message,
      String? openLocation,
      String? image,
      double? topPadding,
      Function()? onTap}) {
    return TransparentPointer(

      child: Column(
        children: [
          (message == null && image == null)
              ? EmptyView.networkView()
              : EmptyView(
                  topPadding: topPadding ??0,
                  image: image,
                  message: message,
                  mainTitle: openLocation,
                ),
          44.verticalSpaceFromWidth,
          CommonButton(
            width: 170,
            title: title ?? '刷新',
            onClick: () {
              onTap != null ? onTap.call() : clickToRefresh();
            },
          )
        ],
      ),
    );
  }

  Widget buildError({String? image, String? message}) {
    return TransparentPointer(
      child: GestureDetector(
        onTap: clickToRefresh,
        child: Center(
          child: EmptyView(
            image: image,
            message: message,
          ),
        ),
      ),
    );
  }

  Widget buildEmpty({String? image, String? message}) {
    return TransparentPointer(
      child: GestureDetector(
        onTap: clickToRefresh,
        child: EmptyView(
          image: image,
          message: message,
        ),
      ),
    );
  }

  void clickToRefresh() {}
}
